import Local_Window_QuestCategories from './windowQuestCategories.js'

//变更窗口生成顺序
Scene_Quest.prototype.create = function() {
  Scene_MenuBase.prototype.create.call(this);
  this.runCustomCode(Yanfly.Quest.createBefore);
  this.createTitleWindow();//
  this.createDataWindow();//
  this.createCategoryWindow();
  this.createListWindow();
  this.processQuestOpen();
  this.runCustomCode(Yanfly.Quest.createAfter);
};

Scene_Quest.prototype.createCategoryWindow = function() {
    this._categoryWindow = new Local_Window_QuestCategories();
    //this._categoryWindow.setHandler('cancel', this.onCategoryCancel.bind(this));
    //this._categoryWindow.setHandler('category', this.onCategoryOk.bind(this));
    this.addWindow(this._categoryWindow);
    // 设置外观基础值
    const [x, y] = [16,40];
    this._categoryWindow.x = x;
    this._categoryWindow.y = y;
};

const originSceneQuestCreateListWindow = Scene_Quest.prototype.createListWindow;
Scene_Quest.prototype.createListWindow = function() {
    originSceneQuestCreateListWindow.call(this);
    this._listWindow._scrollbar.setOffset(5)
    this._listWindow.activate();
    if (this._listWindow.index() < 0) this._listWindow.select(0);
};

const originSceneQuestCreateDataWindow = Scene_Quest.prototype.createDataWindow;
Scene_Quest.prototype.createDataWindow = function() {
  originSceneQuestCreateDataWindow.call(this);
  this._dataWindow._scrollbar.setOffset(5);
};

// 把列表窗口的cancel替换成onCategoryCancel的功能
Scene_Quest.prototype.onListCancel = function() {
    this.runCustomCode(Yanfly.Quest.terminateMenu);
    this.popScene();
};

// 激活Data窗口时禁用分类窗口。
const originSceneQuestOnListQuest = Scene_Quest.prototype.onListQuest;
Scene_Quest.prototype.onListQuest = function() {
  originSceneQuestOnListQuest.call(this);
  this._categoryWindow.deactivate();
};


// 激活Data窗口时禁用分类窗口。
const originSceneQuestOnDataCancel = Scene_Quest.prototype.onDataCancel;
Scene_Quest.prototype.onDataCancel = function() {
  originSceneQuestOnDataCancel.call(this);
  this._categoryWindow.activate();
};
